<template>
  <div>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      class="j-table-force-nowrap"
      :scroll="{ x: true }"
      :columns="confirmColumns"
      :dataSource="confirmList"
    >
      <template slot="action" slot-scope="text, record">
        <a @click="handleDetail(record)">详情</a>
      </template>
    </a-table>
    <qc-report-modal ref="modalForm" />
  </div>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { getAction } from '@api/manage'
import QcReportModal from '@/views/qms/report/modules/QcReportModal.vue'

export default {
  name: 'confirm',
  components: { QcReportModal },
  data() {
    return {
      description: '材料检验信息',
      confirmList: [],
      confirmColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          fixed: 'left',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '入库类型',
          align: 'center',
          dataIndex: 'entryType_dictText',
          width: 80,
          fixed: 'left',
        },
        {
          title: '入库单号',
          align: 'center',
          dataIndex: 'entryNumber',
          width: 80,
          fixed: 'left',
        },
        {
          title: '检验单号',
          align: 'center',
          dataIndex: 'reportNumber',
          width: 80,
          fixed: 'left',
        },
        {
          title: '物料编码',
          align: 'center',
          dataIndex: 'materialCode',
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName',
        },
        {
          title: '规格型号',
          align: 'center',
          dataIndex: 'specificationModel',
        },
        {
          title: '主计量单位',
          align: 'center',
          dataIndex: 'unit_dictText',
        },
        {
          title: '辅计量单位',
          align: 'center',
          dataIndex: 'secondaryUnit_dictText',
        },
        {
          title: '供应商名称',
          align: 'center',
          dataIndex: 'supplierName',
        },
        {
          title: '入库数量',
          align: 'center',
          dataIndex: 'storedQuantity',
        },
        {
          title: '批次号',
          align: 'center',
          dataIndex: 'batchNumber',
        },
        {
          title: '物料批号',
          align: 'center',
          dataIndex: 'materialBatchNumber',
        },
        {
          title: '储位',
          align: 'center',
          dataIndex: 'storageLocation_dictText',
        },
        {
          title: '入库日期',
          align: 'center',
          dataIndex: 'entryDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '制单人',
          align: 'center',
          dataIndex: 'creator_dictText',
        },
        {
          title: '制单部门',
          align: 'center',
          dataIndex: 'creatorDeptCode_dictText',
        },
        {
          title: '制单日期',
          align: 'center',
          dataIndex: 'creationDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '检验标准',
          align: 'center',
          dataIndex: 'inspectionStandard',
        },
        {
          title: '检验数量',
          align: 'center',
          dataIndex: 'samplingQuantity',
        },
        {
          title: '检验结果',
          align: 'center',
          dataIndex: 'inspectionResult',
        },
        {
          title: '检验员',
          align: 'center',
          dataIndex: 'inspector_dictText',
        },
        {
          title: '检验日期',
          align: 'center',
          dataIndex: 'inspectionDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'creatorRemark',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 70,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/qms/inspection/report/allList',
      },
    }
  },
  methods: {
    loadConfirmData(batchNumber, reportType, convert) {
      this.confirmList = []
      if (batchNumber) {
        let params = { pageSize: 999, pageNo: 1 }
        params.reportType = reportType || 'raw-material'
        if (convert) {
          params.planNumber = batchNumber
        } else {
          params.batchNumber = batchNumber
        }
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.confirmList = res.result.records || res.result || []
          }
        })
      }
    },
    handleDetail: function (record) {
      this.$refs.modalForm.detail(record)
      this.$refs.modalForm.title = '详情'
      this.$refs.modalForm.disableSubmit = true
      this.$refs.modalForm.reportType = record.reportType
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
::v-deep .ant-table-tbody tr {
  height: 36px !important;
}
</style>
